Repository navigation
Throw the documented exception for a null, a small RSA key and a plugin's mistake - #147
Merged
Merged
Conversation
…in's mistake From the 2026-11-30 review (S5). A null argument: ten Parse methods and every identity's TryUnwrap threw NullReferenceException. They now throw ArgumentNullException, as the others already did. A small RSA key: SshRsaIdentity.Recipient threw ArgumentException for a key under 2048 bits that Parse had accepted, and a passphrase-protected one was refused when read, so a file made for it could not be opened. As in go-age, an identity of any size now has a recipient and decrypts; the size is checked where a key is read as a recipient, and again when wrapping to it, which is an AgeException. The new test key rsa_1024_aes256ctr was made for this (passphrase hunter2, as the others). A plugin's file key of the wrong size was an AgeFormatException, a malformed file; it is the plugin's mistake, an AgePluginException, and is found where the fuzzer's plugin-client target can see it. An AgePlugin handler that returns null, or a recipient that wraps to a null stanza, was an exception out of Run. It is now that key's error to the client and exit code 3.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #147 +/- ##
==========================================
+ Coverage 97.54% 97.55% +0.01%
==========================================
Files 76 76
Lines 5044 5074 +30
Branches 695 699 +4
==========================================
+ Hits 4920 4950 +30
Misses 76 76
Partials 48 48
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Finding S5 of the 2026-11-30 review. 25 of the 34 new tests failed before the change; a 35th was added for a case the tests then turned up.
A null argument
The review named the SSH parsers. The tests show it was wider: ten
Parsemethods and every identity'sTryUnwrapthrewNullReferenceException. They now throwArgumentNullException, as the other nine parsers already did.A small RSA key
SshRsaIdentity.RecipientthrewArgumentExceptionfor a key under 2,048 bits thatParsehad accepted and that decrypts. The interface documents onlyObjectDisposedException.FormatException), so a file made for it could not be opened at all, while the same key unprotected opened it.As in go-age (
agessh.go:NewRSARecipientandWrapcheck the size,RSAIdentity.Recipientdoes not), an identity of any size now has a recipient and decrypts. The size is checked where a key is read as a recipient (FormatException, as before) and again when wrapping to it (AgeException).The new test key
Age.Tests/TestData/EncryptedSsh/rsa_1024_aes256ctrwas generated for this withssh-keygen -t rsa -b 1024, passphrasehunter2like the folder's other keys. The test builds thessh-rsastanza itself, since neither AgeSharp nor go-age writes one for such a key.A plugin's mistake
AgeFormatException("file key must be 16 bytes"), which blames the file. It is nowAgePluginException, thrown where the plugin's answer is read, which is also where the fuzzer's plugin-client target can see it.AgePluginhandler that returns null, or a recipient that wraps to a null stanza, was an exception out ofRun. It is now that key'serrorto the client and exit code 3.Behaviour changes
Noted in
TODO.mdfor the next release notes. One existing test asserted the internal constructor'sArgumentExceptionand now asserts theFormatExceptionof the publicParse.Checked
dotnet testanddotnet test -c Release -p:ForcePortableAead=true -p:TreatWarningsAsErrors=true: 1,176 vectors and 1,693 unit tests pass.Age.Fuzzonssh,sshpub,plugin,plugin-client,identitiesandrecipientsfor 25 s: no findings.